package com.peanut.baby.db;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by anonymouslystudio on 2017/7/11.
 */

public class DBHelper extends SQLiteOpenHelper{

    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, errorHandler);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DBConfig.TABLE_USER_CREATE_SQL);
        db.execSQL(DBConfig.TABLE_MSG_CREATE_SQL);
        db.execSQL(DBConfig.TABLE_TASK_CREATE_SQL);
//        db.execSQL(DBConfig.TABLE_ADVICE_CREATE_SQL);
//        db.execSQL(DBConfig.TABLE_SIGN_CREATE_SQL);
        db.execSQL(DBConfig.TABLE_CALENDAR_CREATE_SQL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(DBConfig.TABLE_USER_DROP_SQL);
        db.execSQL(DBConfig.TABLE_MSG_DROP_SQL);
        db.execSQL(DBConfig.TABLE_TASK_DROP_SQL);
//        db.execSQL(DBConfig.TABLE_ADVICE_DROP_SQL);
//        db.execSQL(DBConfig.TABLE_SIGN_DROP_SQL);
        db.execSQL(DBConfig.TABLE_CALENDAR_DROP_SQL);
        onCreate(db);
    }
}
